package com.jetinno.utils;

import android.content.res.Resources;
import android.graphics.Color;
import android.support.annotation.ArrayRes;
import android.support.annotation.DimenRes;
import android.support.annotation.StringRes;
import android.text.TextUtils;

public class ResourcesUtil {

    public static Resources getResource() {
        return ContextHolder.getResources();
    }

    public static String getString(@StringRes int id) {
        return getResource().getString(id);
    }

    public static String getString(@StringRes int id, Object... formatArgs) {
        return getResource().getString(id, formatArgs);
    }

    public static int[] getIntArray(@ArrayRes int id) {
        return getResource().getIntArray(id);
    }

    public static float getDimension(@DimenRes int id) {
        return getResource().getDimension(id);
    }

    public static int getColor(String colorString, int defaultColor) {
        try {
            if (!TextUtils.isEmpty(colorString)) {
                int color = Color.parseColor(colorString);
                return color;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return defaultColor;
    }
}
